#include <avr/io.h>
#include <util/delay.h>

void fun_1(void)
{
    while(1)
    {
        PORTD ^= 0b11000000;
        _delay_ms(500);
    }

}

uint8_t stack[100];

/*union
{
    uint16_t add16;
    uint8_t add8[2];
}funAddress;*/


void runFunInNewStack(void (*pfun)(),uint8_t *pstack)
{
    *pstack-- = (uint16_t)pfun ;
    *pstack-- = (uint16_t)pfun >> 8;
    /*funAddress.add16 = (uint16_t)pfun;
    *pstack-- = funAddress.add8[0];
    *pstack-- = funAddress.add8[1];*/
    SP = (uint16_t)pstack;
    __asm__ __volatile__("ret""\t");

}

int main(void)
{

    // Insert code

    //while(1)
    //;
    DDRD = 0xf0;

    //fun_1();
    runFunInNewStack(fun_1,&stack[99]);

    return 0;
}